package model.util.grille;

import model.Agent;
import model.Simulation;
import model.util.CaseSansMarquage;
import model.util.Ressource;


public class GrilleSimpleSansMarquage extends GrilleSansMarquage {

	private Agent exterieur = new Agent(); 
	private CaseSansMarquage[][] data;
	private int s;

	public GrilleSimpleSansMarquage(int size){
		data = new CaseSansMarquage[size][size];
		s = size;
	}

	public byte getRessource(int i, int j){
		if(i >= 0 && j >= 0 && i < s && j < s){
			CaseSansMarquage caseij = data[i][j];
			if (caseij != null)
				return caseij.getRessource();
			else
				return Ressource.NONE;
		}
		else //en dehors de la grille
			return Ressource.NONE;
	}

	public void putRessource(int i, int j, byte val) {
		CaseSansMarquage caseij = data[i][j];
		if (caseij == null)
			data[i][j] = new CaseSansMarquage(val);
		else
			caseij.putRessource(val);
	}

	public byte takeRessource(int i, int j) {
		return data[i][j].takeRessource();
	}


	public Agent getOccupation(int i, int j) {
		if(i >= 0 && j >= 0 && i < s && j < s){
			CaseSansMarquage caseij = data[i][j];
			if (caseij == null)
				return null;
			else
				return caseij.getOccupation();
		}
		else //en dehors de la grille
			return exterieur;
	}

	public void setOccupation(int i, int j, Agent occupe) {
			CaseSansMarquage caseij = data[i][j];
			if (caseij == null)
				data[i][j] = new CaseSansMarquage(occupe);
			else
				caseij.setOccupation(occupe);
	}

}
